package wrapper;

import java.util.StringTokenizer;

import vlms.bean.Person;
import vlms.bean.SimpleCustomer;

public class PersonSC {

	public int getPersonid() {
		return personid;
	}

	public void setPersonid(int personid) {
		this.personid = personid;
	}

	public String getEmailid() {
		return emailid;
	}

	public void setEmailid(String emailid) {
		this.emailid = emailid;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getZipcode() {
		return zipcode;
	}

	public void setZipcode(String zipcode) {
		this.zipcode = zipcode;
	}

	public String getMembertype() {
		return membertype;
	}

	public void setMembertype(String membertype) {
		this.membertype = membertype;
	}

	public String getCreditcardtype() {
		return creditcardtype;
	}

	public void setCreditcardtype(String creditcardtype) {
		this.creditcardtype = creditcardtype;
	}

	public String getCreditcardnum() {
		return creditcardnum;
	}

	public void setCreditcardnum(String creditcardnum) {
		this.creditcardnum = creditcardnum;
	}

	public int getCreditcardcvv() {
		return creditcardcvv;
	}

	public void setCreditcardcvv(int creditcardcvv) {
		this.creditcardcvv = creditcardcvv;
	}

	public String getMembershipno() {
		return membershipno;
	}

	public void setMembershipno(String membershipno) {
		this.membershipno = membershipno;
	}

	public float getBalance() {
		return balance;
	}

	public void setBalance(float balance) {
		this.balance = balance;
	}

	public int getOutstandingmovie() {
		return outstandingmovie;
	}

	public void setOutstandingmovie(int outstandingmovie) {
		this.outstandingmovie = outstandingmovie;
	}

	private int personid;
	private String emailid;
	private String firstname;
	private String lastname;
	private String address;
	private String city;
	private String state;
	private String zipcode;
	private String membertype;
	private String creditcardtype;
	private String creditcardnum;
	private int creditcardcvv;
	
	private String membershipno;
	private float balance;
	private int outstandingmovie;
	
	public static PersonSC convertToPersonSC(String input) throws Exception
	{
		PersonSC psc = new PersonSC();
		
		StringTokenizer str = new StringTokenizer(input, ":#");
		
		if (str.countTokens() != 15)
		{
			psc.personid = Integer.parseInt(str.nextToken());
			psc.emailid = str.nextToken();
			psc.firstname = str.nextToken();
			psc.lastname = str.nextToken();
			psc.address = str.nextToken();
			psc.city = str.nextToken();
			psc.state = str.nextToken();
			psc.zipcode = str.nextToken();
			psc.membertype = str.nextToken();
			psc.creditcardtype = str.nextToken();
			psc.creditcardnum = str.nextToken();
			psc.creditcardcvv = Integer.parseInt(str.nextToken());
			psc.membershipno = str.nextToken();
			psc.balance = Float.parseFloat(str.nextToken());
			psc.outstandingmovie = Integer.parseInt(str.nextToken());			
		}
		else
		{
			throw new Exception("Invalid string provided for populating the " +
								"wrapper.");
		}
		return psc;
	}
	
	public static PersonSC mixObjects(Person person, SimpleCustomer sc)
	{
		PersonSC psc = new PersonSC();
		psc.personid = person.getPersonid();
		psc.emailid = person.getEmailid();
		psc.firstname = person.getFirstname();
		psc.lastname = person.getLastname();
		psc.address = person.getAddress();
		psc.city = person.getCity();
		psc.state = person.getState();
		psc.zipcode = person.getZipcode();
		psc.membertype = person.getMembertype();
		psc.creditcardtype = person.getCreditcardtype();
		psc.creditcardnum = person.getCreditcardnum();
		psc.creditcardcvv = person.getCreditcardcvv();
		psc.membershipno = sc.getMembershipno();
		psc.balance = sc.getBalance();
		psc.outstandingmovie = sc.getOutstandingmovie();
		return psc;
	}
	public static PersonSC[] mixObjects(Person[] person, SimpleCustomer[] sc) 
	{
		PersonSC psc[];
		int length = person.length;
		
		psc = new PersonSC[length];
		
		for (int index = 0; index < length; index++)
		{
			psc[index] = new PersonSC();
			psc[index].personid = person[index].getPersonid();
			psc[index].emailid = person[index].getEmailid();
			psc[index].firstname = person[index].getFirstname();
			psc[index].lastname = person[index].getLastname();
			psc[index].address = person[index].getAddress();
			psc[index].city = person[index].getCity();
			psc[index].state = person[index].getState();
			psc[index].zipcode = person[index].getZipcode();
			psc[index].membertype = person[index].getMembertype();
			psc[index].creditcardtype = person[index].getCreditcardtype();
			psc[index].creditcardnum = person[index].getCreditcardnum();
			psc[index].creditcardcvv = person[index].getCreditcardcvv();
			psc[index].membershipno = sc[index].getMembershipno();
			psc[index].balance = sc[index].getBalance();
			psc[index].outstandingmovie = sc[index].getOutstandingmovie();
		}
		return psc;
	}
	public static String convertToString(PersonSC psc)
	{
		String result = new String();
		
		result = psc.personid+":#" + psc.emailid+":#" + psc.firstname+":#" + psc.lastname+":#" + psc.address
		+":#" + psc.city +":#" + psc.state+":#" + psc.zipcode+":#" + psc.membertype+":#" + psc.creditcardnum+":#" + psc.creditcardtype
		+":#" + psc.creditcardnum +":#" + psc.creditcardcvv+ ":#"+ psc.membershipno + ":#" + psc.outstandingmovie + ":#" + psc.balance;
		return result;
	}
	public static PersonSC[] convertStringToPersonSCArray(String input[]) throws Exception
	{
		PersonSC psc[];
		int inputLen = input.length;
		
		psc = new PersonSC[inputLen];
		
		for (int index = 0; index < inputLen; index++)
		{
			psc[index] = convertToPersonSC(input[index]);
		}
		return psc;
	}
	public static String[] convertPersonSCToStringArr(PersonSC input[])
	{
		String result[];
		int inputLen = input.length;
		
		result = new String[inputLen];
		
		for (int index = 0; index < inputLen; index++)
		{
			result[index] = convertToString(input[index]);
		}
		return result;
	}
}
